package sk.tuke.persistance;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@org.hibernate.annotations.Proxy(lazy = false)
@Table(name = "USER")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Discriminator", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("USER")
public abstract class UserPo implements Serializable {

	private static final long serialVersionUID = 1L;

	public UserPo() {
	}

	@Column(name = "id", nullable = false)
	@Id
	@GeneratedValue(generator = "USER_ID_GENERATOR")
	@org.hibernate.annotations.GenericGenerator(name = "USER_ID_GENERATOR", strategy = "native")
	private long id;

	@Column(name = "number", nullable = false, length = 10, unique = true)
	private String number;

	@Column(name = "salutation", nullable = true, length = 10)
	private String salutation;

	@Column(name = "firstname", nullable = true, length = 45)
	private String firstname;

	@Column(name = "middlename", nullable = true, length = 45)
	private String middlename;

	@Column(name = "lastname", nullable = true, length = 100)
	private String lastname;

	@Column(name = "password", nullable = true, length = 100)
	private String password;

	@Column(name = "email", nullable = true, length = 100)
	private String email;

	@ManyToOne(targetEntity = InsurancePo.class, fetch = FetchType.LAZY)
	@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.LOCK })
	@JoinColumns({ @JoinColumn(name = "insurance_id", referencedColumnName = "id") })
	@org.hibernate.annotations.LazyToOne(value = org.hibernate.annotations.LazyToOneOption.NO_PROXY)
	private InsurancePo insurance;

	@OneToMany(mappedBy = "user", targetEntity = AddressPo.class)
	@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK })
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	private java.util.List<AddressPo> address = new java.util.ArrayList<AddressPo>();

	@OneToMany(mappedBy = "user", targetEntity = PhonePo.class)
	@org.hibernate.annotations.Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK })
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	private java.util.List<PhonePo> phone = new java.util.ArrayList<PhonePo>();

	public void setId(long value) {
		this.id = value;
	}

	public long getId() {
		return id;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getNumber() {
		return number;
	}

	public void setSalutation(String value) {
		this.salutation = value;
	}

	public String getSalutation() {
		return salutation;
	}

	public void setFirstname(String value) {
		this.firstname = value;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setMiddlename(String value) {
		this.middlename = value;
	}

	public String getMiddlename() {
		return middlename;
	}

	public void setLastname(String value) {
		this.lastname = value;
	}

	public String getLastname() {
		return lastname;
	}

	public void setPassword(String value) {
		this.password = value;
	}

	public String getPassword() {
		return password;
	}

	public void setInsurance(InsurancePo value) {
		this.insurance = value;
	}

	public InsurancePo getInsurance() {
		return insurance;
	}

	public void setAddress(java.util.List<AddressPo> value) {
		this.address = value;
	}

	public java.util.List<AddressPo> getAddress() {
		return address;
	}

	public void setPhone(java.util.List<PhonePo> value) {
		this.phone = value;
	}

	public java.util.List<PhonePo> getPhone() {
		return phone;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public String toString() {
		return String.valueOf(getId());
	}

	public boolean equals(Object aObj) {
		if (aObj == this)
			return true;
		if (!(aObj instanceof UserPo))
			return false;
		UserPo user = (UserPo) aObj;
		if (getId() != user.getId())
			return false;
		return true;
	}

	public int hashCode() {
		int hashcode = 0;
		hashcode = hashcode + (int) getId();
		return hashcode;
	}

}
